Skip to content

tree: sanitize free() handling#1038

Merged
igaw merged 1 commit intolinux-nvme:masterfrom
martin-gpy:free_handling
Jul 22, 2025
Merged

tree: sanitize free() handling#1038
igaw merged 1 commit intolinux-nvme:masterfrom
martin-gpy:free_handling

Conversation

@martin-gpy
Copy link
Copy Markdown
Contributor

As per the POSIX manual, free() is NULL-safe i.e. we could call it without first checking whether the respective pointer is non-NULL. So apply that here. And while at it, reorder some of the cleanup_free items in the declaration section.

Suggested-by: Martin Belanger [email protected]

@martin-gpy martin-gpy force-pushed the free_handling branch 2 times, most recently from de8ca5a to 845c2c2 Compare July 18, 2025 16:50
Comment thread src/nvme/fabrics.c
_cleanup_free_ char *h = NULL;
_cleanup_free_ char *scheme = NULL, *authority = NULL;
_cleanup_free_ char *path = NULL, *h = NULL;
const char *host;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary code churn.

Comment thread src/nvme/log.c Outdated
};
_cleanup_free_ char *header = NULL;
_cleanup_free_ char *message = NULL;
_cleanup_free_ char *header = NULL, *message = NULL;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Comment thread src/nvme/tree.c Outdated
_cleanup_free_ char *nqn = NULL;
_cleanup_free_ char *hid = NULL;
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *nqn = NULL, *hid = NULL, *hnqn = NULL;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again nothing changes.

Comment thread src/nvme/tree.c Outdated
{
_cleanup_free_ char *hostnqn = NULL;
_cleanup_free_ char *hostid = NULL;
_cleanup_free_ char *hostnqn = NULL, *hostid = NULL;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one of code churn, nothign gained, makes the review more harder, makes backporting harder.

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Jul 22, 2025

I'll fix it up myself.

As per the POSIX manual, free() is NULL-safe i.e. we could call it
without first checking whether the respective pointer is non-NULL.
So apply that here.

Suggested-by: Martin Belanger <[email protected]>
Signed-off-by: Martin George <[email protected]>
@igaw igaw merged commit 69e2440 into linux-nvme:master Jul 22, 2025
12 checks passed
@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Jul 22, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants